package file

import (
	"context"
	"fmt"
	"net/http"

	"2106A-zg6/baidu/gateway/internal/svc"
	"2106A-zg6/baidu/gateway/internal/types"
	"2106A-zg6/baidu/srv/baiduclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetWpFileLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetWpFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWpFileLogic {
	return &GetWpFileLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetWpFileLogic) GetWpFile(req *types.FileGetAll) (resp *types.Response, err error) {

	//  获取 用户ID
	value := l.ctx.Value("custom-key")

	if req.UserId != value {
		return &types.Response{
			Msg:  "token错误 ，请从新登录",
			Code: http.StatusAccepted,
			Data: nil,
		}, err
	}

	file, err := l.svcCtx.BaiduSrv.GetFile(l.ctx, &baiduclient.GetFileRequest{
		UserId: fmt.Sprintf("%v", value),
	})

	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: http.StatusAccepted,
			Data: nil,
		}, err
	}

	return &types.Response{
		Msg:  "successful",
		Code: http.StatusOK,
		Data: file,
	}, nil
}
